import { asyncIncre, decre, incre, selectCount } from '@/app/slices/countSlice';
import React from 'react'
import { useAppDispatch, useAppSelector } from '@/app/hooks';
export default function ReduxCom() {
  //获取状态
  let state = useAppSelector(selectCount);
  //获取 dispatch 函数
  let dispatch = useAppDispatch();
  //更新状态
  let add = () => {
    dispatch(incre(1));
  }

  let sub = () => {
    dispatch(decre(1));
  }

  let asyncAdd = () => {
    dispatch(asyncIncre(1))
  }
  return (
    <div>
      <h2>{state}</h2>
      <hr />
      <button onClick={add}>新增</button>
      <button onClick={sub}>减少</button>
      <button onClick={asyncAdd}>异步</button>
    </div>
  )
}
